package com.example.framelib;

import android.app.Application;

import com.example.framelib.api.LoggerInterceptor;
import com.example.framelib.cons.Cons;
import com.example.framelib.okhttp.OkHttpUtils;
import com.example.framelib.utils.SPUtils;
import com.facebook.stetho.okhttp3.StethoInterceptor;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

public class FrameApp extends Application {
    private static FrameApp mInstance;

    @Override
    public void onCreate() {
        super.onCreate();

        //Retrofit上传文件不如OkHttpUtils简便
        OkHttpClient client = new OkHttpClient.Builder()
                .addNetworkInterceptor(new StethoInterceptor())
                .addInterceptor(new LoggerInterceptor("TAG"))
                .connectTimeout(10000L, TimeUnit.MILLISECONDS)
                .readTimeout(10000L, TimeUnit.MILLISECONDS)
                //其他配置
                .build();

        OkHttpUtils.initClient(client);

        mInstance = this;
        initSpUtils();
    }

    private void initSpUtils() {
        SPUtils.init(this, Cons.SPCons.SP_NAME);
    }

    public static FrameApp  getApplication(){
        return mInstance;
    }

}
